#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QImage>
#include <QColor>
#include <QRandomGenerator>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    imageSend = new ImageSender();
}

MainWindow::~MainWindow()
{
    delete ui;
}


void MainWindow::on_pushButton_clicked()
{
    // 创建一个 640x480 的图像
       int width = 640;
       int height = 480;
       QImage image(width, height, QImage::Format_ARGB32);

       // 随机填充图像
       for (int y = 0; y < height; ++y)
       {
           for (int x = 0; x < width; ++x)
           {
               // 生成随机颜色
               int r = QRandomGenerator::global()->bounded(256);
               int g = QRandomGenerator::global()->bounded(256);
               int b = QRandomGenerator::global()->bounded(256);
               int a = QRandomGenerator::global()->bounded(256); // 透明度

               image.setPixel(x, y, qRgba(r, g, b, a));
           }
       }
       ui->label->setPixmap(QPixmap::fromImage(image));
       image.save("./pngtest.png","png");
       imageSend->sendImage(image,"127.0.0.1",8080);
}
